/**
 * 
 */
package com.gr.staffpm.widget.calendar.event;

import java.io.Serializable;
import java.util.Date;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;

import com.gr.staffpm.datatypes.Task;


/**
 * @author Graham Rhodes 5 Jan 2011 16:20:14
 */
public class TaskEvent extends Panel implements Event, Serializable {

    private static final long serialVersionUID = 1L;
    private final Task task;

    public TaskEvent(String id, Task task) {
        super(id);
        this.task = task;

        add(new Label("eventName", getTitle()).setOutputMarkupId(true));
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.widget.calendar.event.Event#getCalId()
     */
    @Override
    public String getCalId() {
        return "Event_" + task.getTaskId();
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.widget.calendar.event.Event#getTitle()
     */
    @Override
    public String getTitle() {
        return "Task " + task.getName() + " due.";
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.widget.calendar.event.Event#isAllDay()
     */
    @Override
    public boolean isAllDay() {
        return true;
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.widget.calendar.event.Event#getStart()
     */
    @Override
    public Date getStart() {
        return task.getDueDate();
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.widget.calendar.event.Event#getEnd()
     */
    @Override
    public Date getEnd() {
        return task.getDueDate();
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.widget.calendar.event.Event#getURL()
     */
    @Override
    public String getURL() {
        return null;
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.widget.calendar.event.Event#getCSSClass()
     */
    @Override
    public String getCSSClass() {
        return null;
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.widget.calendar.event.Event#isLocked()
     */
    @Override
    public boolean isLocked() {
        return true;
    }

    /* (non-Javadoc)
     * @see org.apache.wicket.markup.html.panel.Panel#onComponentTag(org.apache.wicket.markup.ComponentTag)
     */
    @Override
    protected void onComponentTag(ComponentTag tag) {
        super.onComponentTag(tag);
        if (isAllDay())
            tag.getAttributes().put("class", "cal-evt evt-all-day");
        else
            tag.getAttributes().put("class", "cal-evt");
    }

}
